package com.gxan.web.renshi;

import com.alibaba.fastjson.JSONObject;
import com.gxan.renshiservice.ServiceArchives;
import com.gxan.renshiservice.impl.ServiceArchivesImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/archives/del")
public class DelArchivesServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        Map map = new HashMap();
        Integer archives_id = Integer.valueOf(req.getParameter("archives_id"));
        ServiceArchives serviceArchives = new ServiceArchivesImpl();
        try {
            int num = serviceArchives.delArchives(archives_id);
            if (num>0){
                map.put("code",0);
                map.put("msg","删除成功");
                resp.getWriter().write(JSONObject.toJSONString(map));
            }
        } catch (SQLException e) {
            e.printStackTrace();
            map.put("code",-1);
            map.put("msg","删除失败");
            resp.getWriter().write(JSONObject.toJSONString(map));
        }
        resp.getWriter().flush();
        resp.getWriter().close();
    }
}
